﻿using SteamWebAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Stack_Check
{
    //ListBoxItem
    class HistoryListItem : ItemsControl
    {
        private GameSession session;

        public event ItemDeletedEventHandler ItemDeleted;

        private Button buttonDelete = new Button();

        public bool Selected
        {
            get;
            set;
        }

        public GameSession Session
        {
            get { return this.session; }
        }

        public HistoryListItem(GameSession session)
        {
            this.session = session;

            Label label = new Label(); 
            label.Content = session;
            label.Height = 25;
            Thickness margin = buttonDelete.Margin;
            margin.Top = -25;
            margin.Right = -30;
            buttonDelete.Margin = margin;

            buttonDelete.Click += buttonDelete_Click;
            buttonDelete.Content = "×";
            buttonDelete.Height = 20;
            buttonDelete.FontWeight = FontWeights.Bold;
            buttonDelete.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            buttonDelete.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            buttonDelete.Foreground = Brushes.Red;

            this.AddChild(label);
            this.AddChild(buttonDelete);
        }

        void buttonDelete_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Opravdu si přejete smazat vybraný záznam?", "Game history", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation, MessageBoxResult.Cancel);
            if (result.HasFlag(MessageBoxResult.OK))
            {
                if (ItemDeleted != null)
                {
                    ItemDeleted(this, new ItemDeletedEventArgs(this.Session));
                }
            }
        }

       

        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
        }
    }
}
